/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include "Texture.h"
#include <safe_new.h>
#include <xml/Stream.h>
#include <lib3d/hard/Hardware.h>
#include <Converter.h>

namespace liba {
namespace lib3d {
namespace material {

const Atom Texture::wrap_name("Wrap");
const Atom Texture::factor_name("Factor");
const Atom Texture::image_name("Image");

Texture::Texture(const Atom & name, bool wrap)
	: animate::Node( name )
	, wrap( wrap )
{
	this->RegisterProperty(wrap_name, &this->wrap);
}

Texture * Texture::Clone()const
{
	return new Texture(*this);
}

int Texture::get_mipmap_levels(pictureformat::Loader * pl)
{
	if( pl->get_frame_count() == 0 )
		return 0;
	int width = pl->get_width(0);
	int height = pl->get_height(0);
	int mipmap_levels = 1;
	for( ; mipmap_levels != pl->get_frame_count(); ++mipmap_levels )
	{
		if( (pl->get_width(mipmap_levels) << mipmap_levels) != width )
			break;
		if( (pl->get_height(mipmap_levels) << mipmap_levels) != height )
			break;
	}
	return mipmap_levels;
}


} // namespace material
} // namespace lib3d
} // namespace liba

